﻿
/*
 * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：研发部
 * 日 期：2017.04.05
 * 描 述：功能模块	
 */
var objectId = request('objectId');
var objectType = request('objectType');
var parentId = request('parentId');

var bootstrap = function ($, learun) {
    "use strict";

    var selectData;

    var treeData;
    var checkModuleIds = [];

    function setTreeData1() {
        if (!!selectData) {
            setTimeout(function () {
                $('#step-1').lrtreeSet('setCheck', selectData.modules);
            });
        }
        else {
            setTimeout(setTreeData1,100);
        }
    }

    var page = {
        init: function (parentId) {
            page.bind(parentId);
            page.initData();
        },
        /*绑定事件和初始化控件*/
        bind: function (parentId) {
            learun.loading(true, '正在获取数据');
            learun.httpAsyncGet(top.$.rootUrl + '/LR_SystemModule/Module/GetCheckTree?parentId=' + parentId, function (res) {
                if (res.code == 200) {
                    treeData = res.data;
                    $('#step-1').lrtree({
                        data: treeData.moduleList
                    });
                    if (!!objectId) {
                        setTreeData1();
                    }
                }
                setTimeout(function () {
                    learun.loading(false);
                });
            });
            // 保存数据按钮
            $("#btn_finish").on('click', page.save);
        },
        /*初始化数据*/
        initData: function () {
            if (!!objectId) {
                learun.httpAsyncGet(top.$.rootUrl + '/LR_AuthorizeModule/Authorize/GetFormData?objectId=' + objectId, function (res) {//
                    if (res.code == 200) {
                        selectData = res.data;
                    }
                    else {
                        selectData = [];
                    }
                });
            }
        },
        /*保存数据*/
        save: function () {
            var buttonList = [], columnList = [],formList = [];
            checkModuleIds = $('#step-1').lrtreeSet('getCheckNodeIds');
            var postData = {
                objectId: objectId,
                objectType: objectType,
                strModuleId: String(checkModuleIds),
                strModuleButtonId: String(buttonList),
                strModuleColumnId: String(columnList),
                strModuleFormId: String(formList)
            };

            $.lrSaveForm(top.$.rootUrl + '/LR_AuthorizeModule/Authorize/SaveForm', postData, function (res) {});
        }
    };
    page.init(parentId);
    
}